//
//  ImageView.swift
//  SwiftUIDemo
//
//  Created by zuosong on 2019/11/4.
//  Copyright © 2019 Kael. All rights reserved.
//

import SwiftUI


struct ImageView: View {
    
    @State var BGColor = Color.red
    @State var textColor = Color.white
    @State var isOn = true
    
    
    var body: some View {
        VStack {
            Image("boy")
                .resizable()
                .frame(width: 100, height: 100, alignment: .center)
                .background(Color.orange)
                .clipShape(Circle())
                .overlay(Circle().stroke(Color.white, lineWidth: 2))
//                .shadow(color: .red, radius: 6, x: -3, y: 3)
                .onAppear(perform: kaelImageAction)
                .onTapGesture(perform: changeColor)
            
            Text("鱼跃此时海，花开彼岸天")
                .frame(width: 200, height: 40, alignment: .bottom)
                .foregroundColor(self.textColor)
            Toggle(isOn: $isOn) {
                Text("State: \(self.isOn == true ? "开":"关")")
                    .foregroundColor(.white)
            }.padding(20)
        }
        .background(self.BGColor)
    }
    
    func kaelImageAction() -> Void {
        self.BGColor = Color.red
    }
    func changeColor() -> Void {
        if self.BGColor == Color.gray {
            self.BGColor = Color.red
            self.textColor = Color.white
        }else{
            self.BGColor = Color.gray
            self.textColor = Color.black
        }
        
    }
}

struct ImageView_Previews: PreviewProvider {
    static var previews: some View {
        ImageView()
    }
}
